const client = require('../utils/redis');
const sql = require('../utils/sql');
const Token = require('../utils/token')
const tb = 'users';
class UsersCtl {
    async create(ctx) {
        const username = ctx.request.body.username
        const password = ctx.request.body.password
        const phone = ctx.request.body.phone
        const data = await sql.insert(tb, {username:username,password:password,phone:phone});
        ctx.body = data;
        
    }
    async login(ctx){
        const username = ctx.request.body.username
        const password = ctx.request.body.password
        const data = await sql.oneTabSearch(tb,["username"],{username:username,password:password})
        if(data["code"]==200){
            const token = Token.encrypt({"username":username},60)
            data["token"] = token
            
        }
        ctx.body = data
    }
}

module.exports = new UsersCtl;
